using System;
using System.Collections;
using System.Collections.Generic;
using Game.Combat;
using Game.Combat.Damage;
using UnityEngine;
using Collider = Game.Collider;

public class Bullet : Collider {
    public Action OnUpdate;
    public float Damage;//子弹伤害
    public float Speed;//子弹飞行速度
    public Vector3 Direction;//子弹飞行方向

    private void Update() {
        base.Update();
        OnUpdate?.Invoke();
        move();
    }

    private void move() {
        transform.localPosition += (Direction * Speed * Time.deltaTime);
    }

    protected override void onColliderEnter(Collider2D collider) {
        var hitObj = collider.gameObject.GetComponent<IDamageable>();
        if (hitObj != null) {
            hitObj.AddDamage(new DamageParam() {
                Type = eDamageType.Weapon,
                Damage = Damage
            });
            Destroy(gameObject);
        }
    }
}
